﻿using JiveMessenger.Models;
using JiveMessenger.User;
using JiveMessenger.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Windows.ApplicationModel;
using Windows.UI.Xaml;


namespace JiveMessenger.Utilities.TemplateSelector
{
    public class UserTemplateSelector : DataTemplateSelector
    {
        public DataTemplate MyTemplate
        {
            get;
            set;
        }
        public DataTemplate TheirTemplate
        {
            get;
            set;
        }
        public DataTemplate SystemTemplate
        {
            get;
            set;
        }

        public override DataTemplate SelectTemplate(
            object item, DependencyObject container)
        {
            if (item != null)
            {
                if (DesignMode.DesignModeEnabled)
                {
                    Random rnd = new Random();
                    int n = rnd.Next(1, 10);
                    if (n >= 1 && n <= 5)
                        return TheirTemplate;
                    //else
                    //    return MyTemplate;
                    else if (n > 5 && n <= 8)
                        return MyTemplate;
                    else
                        return SystemTemplate;
                }
                MessageModel itemAux = item as MessageModel;

                if (itemAux.Type == MessageModelType.Outgoing)
                    return MyTemplate;
                else if (itemAux.Type == MessageModelType.Incoming)
                    return TheirTemplate;
                else if (itemAux.Type == MessageModelType.SystemMessage)
                    return SystemTemplate;
            }

            return base.SelectTemplate(item, container);
        }
    }
}
